package com.groupbuying.sysconfig.controller;

import com.groupbuying.sysconfig.domain.SysconfigFunctionControlDO;
import com.groupbuying.sysconfig.service.SysconfigFunctionControlService;
import com.groupbuying.sysconfig.utils.PageUtils;
import com.groupbuying.sysconfig.utils.Query;
import com.groupbuying.sysconfig.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 功能控制表
 * 
 * @author vincentxin
 * @email vincentxin@aliyun.com
 * @date 2019-06-24 07:37:21
 */
 
@RestController
@RequestMapping("/functionControl")
public class SysconfigFunctionControlController {
	@Autowired
	private SysconfigFunctionControlService sysconfigFunctionControlService;

	@GetMapping("/list")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<SysconfigFunctionControlDO> sysconfigFunctionControlList = sysconfigFunctionControlService.list(query);
		int total = sysconfigFunctionControlService.count(query);
		PageUtils pageUtils = new PageUtils(sysconfigFunctionControlList, total);
		return pageUtils;
	}

	@GetMapping("/getUrlByCenterCode")

	public List<String> getUrlByCenterCode(String centerCode){
		return sysconfigFunctionControlService.getUrls(centerCode);
	}

	/**
	 * 保存
	 */
	@PostMapping("/save")
	public R save( SysconfigFunctionControlDO sysconfigFunctionControl){
		if(sysconfigFunctionControlService.save(sysconfigFunctionControl)>0){
			return R.ok();
		}
		return R.error();
	}

	/**
	 * 修改
	 */
	@RequestMapping("/update")
	public R update(SysconfigFunctionControlDO sysconfigFunctionControl){
		sysconfigFunctionControlService.update(sysconfigFunctionControl);
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	public R remove( Integer id){
		if(sysconfigFunctionControlService.remove(id)>0){
		return R.ok();
		}
		return R.error();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	public R remove(@RequestParam("ids[]") Integer[] ids){
		sysconfigFunctionControlService.batchRemove(ids);
		return R.ok();
	}
	
}
